package cn.com.fuhuitong.main.home.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.base.SafeMutableLiveData
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.*
import cn.com.fuhuitong.main.home.mode.HomeManager
import io.reactivex.disposables.Disposable

class EnrollViewModel(application: Application) : BaseViewModel(application) {

    private val homeManager: HomeManager = HomeManager()

    val baseDataLiveData = MutableLiveData<HttpResponse<BaseResponse>>()

    fun enrollWelfare(
        name: String,
        sex: String,
        year: String,
        address: String,
        id_num: String,
        mobile: String,
        objective: String
    ) {
        val listener =
            object : ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val enrollDisposable: Disposable = homeManager.enrollWelfare(
            BaseApplication.userToken(),
            name,
            sex,
            year,
            address,
            id_num,
            mobile,
            objective,
            listener
        )
        dispose.add(enrollDisposable)
    }

    fun enrollRecuperate(
        name: String,
        sex: String,
        year: String,
        address: String,
        id_num: String,
        mobile: String,
        disease: String,
        treatment_record: String,
        heard_record:String,
        existing_symptoms: String,
        physical_condition: String,
        disclaimer: String,
        conditioning: String
    ) {
        val listener =
            object : ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val enrollDisposable: Disposable = homeManager.enrollRecuperate(
            BaseApplication.userToken(),
            name,
            sex,
            year,
            address,
            id_num,
            mobile,
            disease,
            treatment_record,
            heard_record,
            existing_symptoms,
            physical_condition,
            disclaimer,
            conditioning,
            listener
        )
        dispose.add(enrollDisposable)
    }

    fun enrollElderly(
        name: String,
        sex: String,
        year: String,
        address: String,
        id_num: String,
        mobile: String
    ) {
        val listener =
            object : ViewModelSubscribeListener<BaseResponse>(baseDataLiveData) {}
        val enrollDisposable: Disposable = homeManager.enrollElderly(
            BaseApplication.userToken(),
            name,
            sex,
            year,
            address,
            id_num,
            mobile,
            listener
        )
        dispose.add(enrollDisposable)
    }
}